package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import java.util.Collection; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXALopMonHoc;
import com.lb.jwitter.service.TblQLDTTXALopMonHocService;
import com.lb.jwitter.service.TblQLDTTXAMonHoc;
import com.lb.jwitter.service.TblQLDTTXAMonHocService;

import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNam;
import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNamService;

import com.lb.jwitter.service.TblQLDTTXAGiaoVien;
import com.lb.jwitter.service.TblQLDTTXAGiaoVienService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXALopMonHocUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private int monHocId; 
    public void setMonHocId(int monHocId) {
       this.monHocId = monHocId;
 }

    public int getMonHocId() {
       return monHocId;
 }

    private int hocKyId; 
    public void setHocKyId(int hocKyId) {
       this.hocKyId = hocKyId;
 }

    public int getHocKyId() {
       return hocKyId;
 }

    private int giaoVienId; 
    public void setGiaoVienId(int giaoVienId) {
       this.giaoVienId = giaoVienId;
 }

    public int getGiaoVienId() {
       return giaoVienId;
 }

    private String maLop; 
    public void setMaLop(String maLop) {
       this.maLop = maLop;
 }

    public String getMaLop() {
       return maLop;
 }
    private String ghiChu; 
    public void setGhiChu(String ghiChu) {
       this.ghiChu = ghiChu;
 }

    public String getGhiChu() {
       return ghiChu;
 }
    
    
    int thoiGianKiemTraGK;
    

    public int getThoiGianKiemTraGK() {
		return thoiGianKiemTraGK;
	}

	public void setThoiGianKiemTraGK(int thoiGianKiemTraGK) {
		this.thoiGianKiemTraGK = thoiGianKiemTraGK;
	}
	
	int thoiGianThi;

	public int getThoiGianThi() {
		return thoiGianThi;
	}

	public void setThoiGianThi(int thoiGianThi) {
		this.thoiGianThi = thoiGianThi;
	}

	private TblQLDTTXALopMonHoc tblQLDTTXALopMonHoc; 
    public void setTblQLDTTXALopMonHoc (TblQLDTTXALopMonHoc tblQLDTTXALopMonHoc) {
        this.tblQLDTTXALopMonHoc = tblQLDTTXALopMonHoc;
 }

    private Collection<TblQLDTTXALopMonHoc> tblQLDTTXALopMonHocs; 
    public void setTblQLDTTXALopMonHocs(Collection<TblQLDTTXALopMonHoc> tblQLDTTXALopMonHocs) {
        this.tblQLDTTXALopMonHocs = tblQLDTTXALopMonHocs; 
      } 

    private TblQLDTTXALopMonHocService tblQLDTTXALopMonHocService; 

    private TblQLDTTXAMonHocService tblQLDTTXAMonHocService; 

    private TblQLDTTXAHocKyTrongNamService tblQLDTTXAHocKyTrongNamService; 

    private TblQLDTTXAGiaoVienService tblQLDTTXAGiaoVienService; 

	private int preUpdate(Message msg, TblQLDTTXALopMonHoc obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblQLDTTXALopMonHoc obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_LopMonHoc", "sua")){ 
        return "noprivilege"; 
    }
        tblQLDTTXALopMonHocService = (TblQLDTTXALopMonHocService) context.getBean("tbl_QLDTTXA_LopMonHocClient"); 
        tblQLDTTXAMonHocService = (TblQLDTTXAMonHocService) context.getBean("tbl_QLDTTXA_MonHocClient"); 

        tblQLDTTXAHocKyTrongNamService = (TblQLDTTXAHocKyTrongNamService) context.getBean("tbl_QLDTTXA_HocKyTrongNamClient"); 

        tblQLDTTXAGiaoVienService = (TblQLDTTXAGiaoVienService) context.getBean("tbl_QLDTTXA_GiaoVienClient"); 

        msg = new Message(); 
        tblQLDTTXALopMonHoc = tblQLDTTXALopMonHocService.gettblQLDTTXALopMonHoc(new Long(id)); 
        tblQLDTTXALopMonHoc.setMaLop(maLop);
        //tblQLDTTXALopMonHoc.setMonHocId(tblQLDTTXAMonHocService.gettblQLDTTXAMonHoc(new Long(monHocId))); 
        //tblQLDTTXALopMonHoc.setHocKyId(tblQLDTTXAHocKyTrongNamService.gettblQLDTTXAHocKyTrongNam(new Long(hocKyId))); 
        tblQLDTTXALopMonHoc.setGiaoVienId(tblQLDTTXAGiaoVienService.gettblQLDTTXAGiaoVien(new Long(giaoVienId))); 
        tblQLDTTXALopMonHoc.setGhiChu(ghiChu);
        tblQLDTTXALopMonHoc.setThoiGianKiemTraGK(thoiGianKiemTraGK);
        tblQLDTTXALopMonHoc.setThoiGianThi(thoiGianThi);
        preUpdate(msg,tblQLDTTXALopMonHoc); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXALopMonHocService.updatetblQLDTTXALopMonHoc(tblQLDTTXALopMonHoc); 
           postUpdate(msg, tblQLDTTXALopMonHoc); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_QLDTTXA_LopMonHoc Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
